// spritewindow.h : contains the class definition for the window that allows for
// sprite modification and setup
//$Id: SpriteWindow.h 34 2009-08-29 17:06:40Z brwarner2 $
#include "WindowFactory.h"

#pragma once

class CSpriteWindow
{
public:
	CSpriteWindow(void);
	~CSpriteWindow(void);

	//Handles the messaging
	LRESULT Message( UINT, WPARAM, LPARAM );

	//Sends information to the window factory
	static void WindowInfo( WindowInfo& info );

	//Sets the window
	void SetHWND( HWND hWnd ) { m_hWindow = hWnd; }

	//Loads an image from a file
	void LoadImageFile( const std::string& filename );

	//Registers the child windows used by the sprite window
	static void RegisterClasses( void );

private:

	//HWND
	HWND m_hWindow;

	//The up/down  FPS control and its buddy
	//0 = UD 1 = Buddy 2 = Static
	HWND m_hFPS[3];
	const static DWORD IDU_FPS = 102;
	const static DWORD IDE_FPS = 103;

	//The up/down Width control and its buddy
	HWND m_hWidth[3];
	const static DWORD IDU_WIDTH = 104;
	const static DWORD IDE_WIDTH = 105;

	//The up/down Height control and its buddy
	HWND m_hHeight[3];
	const static DWORD IDU_HEIGHT = 106;
	const static DWORD IDE_HEIGHT = 107;

	//The up/down Depth control and its buddy
	HWND m_hDepth[3];
	const static DWORD IDU_DEPTH = 108;
	const static DWORD IDE_DEPTH = 109;

	//The up/down Frames# control and its buddy
	HWND m_hFrames[3];
	const static DWORD IDU_FRAMES = 112;
	const static DWORD IDE_FRAMES = 113;

	//The preview window
	HWND m_hPreview;

	//The image box
	HWND m_hIB;
	const static DWORD IDIB_IMAGE = 110;

	//Play and pause buttons
	//0 = Play 1 = Pause
	HWND m_hPlay[2];

	//Identifiers for the play and pause buttons
	const static DWORD IDB_PLAY = 100;
	const static DWORD IDB_PAUSE = 101;

	//Save button
	HWND m_hSave;
	const static DWORD IDB_SAVE = 111;

	//Creates the controls for the window
	void CreateControls( void );

	//Custom paint override
	void Paint( HDC );

	//Unique identifier for the FPS timer
	const static unsigned int FRAME_TIMER = 0;

	//Sprite object
	Gdiplus::Image* m_pSprite;

	//Filename of loaded sprite
	std::string m_spriteFile;

	//Image information
	unsigned int m_width;
	unsigned int m_height;
	unsigned int m_nFPS;
	unsigned int m_nFrames;

	//Update child message
	const static unsigned int WM_UPDATECHILD = (WM_APP+1);

	//Structure to hold image information
	struct ImageInfo
	{
		//Currently loaded sprite image
		Gdiplus::Image* sprite;

		//Current frame
		unsigned int currentFrame;

		//Number of frames
		unsigned int frames;

		//Framerate
		unsigned int fps;

		//Is it playing
		bool playing;

		//Timer identifier
		unsigned int timerID;
	};

	//Structure for holding information of the Image Box
	struct ImageBoxInfo
	{
		//Currently loaded sprite image
		Gdiplus::Image* sprite;

		//Width and height
		unsigned int width, height;

		//Are we being "dragged"
		bool bDragged;
	};

	//Loads an info file
	void LoadInfoFile( const std::string &filename );

	//Saves an info file
	void SaveInfoFile( const std::string &filename );

	//Formats the windows controls based on the new size
	void PositionControls( void );

private:
	//Window procedure for the preview box
	static LRESULT CALLBACK PreviewWindowCallback( HWND, UINT, WPARAM, LPARAM );

	//Window messages for it
	const static unsigned int WM_SETSPRITE = (WM_USER);
	const static unsigned int WM_SETFPS = (WM_USER+1);
	const static unsigned int WM_SETFRAMES = (WM_USER+2);
	const static unsigned int WM_PLAY = (WM_USER+3);

	//Window procedure for the image selection box
	static LRESULT CALLBACK ImageBoxCallback( HWND, UINT, WPARAM, LPARAM );

	//Window messages for it
	const static unsigned int WM_SETIMGRECT = (WM_USER+4);
	const static unsigned int IBN_CLICKRECT = (0);
	struct NMHDIBCLICK
	{
		NMHDR hdr;
		RECT newRect;
	};
};